import type { RouteRecordRaw } from "vue-router";

/** 根路径[!!!必设重定向] */
export const rootPath = "/";

/** 首页路径 */
export const homePath = "/home";

/** 登录路径 */
export const loginPath = "/login";

/** 注册路径 */
export const registerPath = "/register";

/** 404路径 */
export const noFoundPath = "/404";

/** 无权限路径 */
export const noPermissionPath = "/403";

/** 登录免检路径 */
export const loginNoCheckPath = [
  rootPath,
  loginPath,
  registerPath,
  noFoundPath,
  noPermissionPath,
];

/** 权限免检路径 */
export const authNoCheckPath = [
  rootPath,
  loginPath,
  registerPath,
  noFoundPath,
  noPermissionPath,
];

/** 扁平化路由一级、二级，不递归
 * 除通用页面外，一级一般是模块，二级才是具体的页面，第一级的keepAlive如果只管一级不管二级意义其实不大，
 * 不处理三级及以上，因为三级及以上的路由一般是页面内部的路由，keepAlive差别自行处理
 */
export const flatRoutes = (routes: RouteRecordRaw[]): RouteRecordRaw[] => {
  const list: RouteRecordRaw[] = [];
  routes.forEach((route) => {
    list.push(route);
    if (route.children) {
      route.children.forEach((child) => {
        list.push({
          ...child,
          path: `${route.path}/${child.path}`,
        });
      });
    }
  });
  return list;
};
